package c.x.jy.admin.controller;

import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Map;

import c.x.jy.common.annotation.IntoSet;
import c.x.jy.dao.dto.BusinessWalletEntityDto;
import c.x.jy.dao.entity.MemberEntity;
import c.x.jy.dao.entity.SysUserEntity;
import c.x.jy.service.config.BusinessConfigService;
import c.x.jy.service.service.MemberService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import c.x.jy.dao.entity.BusinessWalletEntity;
import c.x.jy.service.service.BusinessWalletService;
import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;



/**
 * 商家钱包表
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-21 11:28:25
 */
@RestController
@RequestMapping("business/businesswallet")
public class BusinessWalletController extends AbstractController {
    @Autowired
    private BusinessWalletService businessWalletService;
    @Autowired
    private BusinessConfigService businessConfigService;
    /**
     * 信息
     */
    @IntoSet(Includefields = {"businessName","pickCashFee"})
    @RequestMapping("/currinfo")
    @RequiresPermissions("business:businesswallet:info")
    public R currinfo(){
        SysUserEntity memberEntity = getUser();

        if(getUser().getBusinessId()==0) {
            return R.error("非商家账号，不能执行");
        }

        BusinessWalletEntityDto businessWallet=null;
        if(memberEntity!=null)
        businessWallet = businessWalletService.getDtoById(memberEntity.getBusinessId());


        return R.put(businessWallet);
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:businesswallet:list")
    public R list(@RequestParam Map<String, Object> params){
     	if(getUser().getBusinessId()>0) {
    		params.put("businessId", getUser().getBusinessId());
    	}
        PageUtils page = businessWalletService.queryPage(params);

        return R.put(page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:businesswallet:info")
    public R info(@PathVariable("id") Long id){
		BusinessWalletEntity businessWallet = businessWalletService.getById(id);

        return R.put(businessWallet);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:businesswallet:save")
    public R save(@RequestBody BusinessWalletEntity businessWallet){
		businessWalletService.save(businessWallet);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:businesswallet:update")
    public R update(@RequestBody BusinessWalletEntity businessWallet){
		businessWalletService.updateById(businessWallet);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("business:businesswallet:delete")
    public R delete(@PathVariable("id") Long id){
		businessWalletService.removeByIds(Arrays.asList(id));

        return R.ok();
    }

}

